package com.example.myproject.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {
    private static final String TORRENTS_DIR = "./torrent/";

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 保留 Spring Boot 默认的静态资源路径
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/", "classpath:/public/", "classpath:/resources/")
                .resourceChain(false);

        registry.addResourceHandler("/torrent/**")
                .addResourceLocations("file:" + TORRENTS_DIR)
                .setCachePeriod(0);

        registry.addResourceHandler("/avatars/**")
                .addResourceLocations("file:" +"./avatars/")
                .setCachePeriod(0);

        // Swagger 相关配置（保持原有逻辑）
        registry.addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
        registry.addResourceHandler("/swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
